package leetcode_动态规划._01斐波那契数列;

/**
 * 打家劫舍 II
 * 算法：
 *   拆分成两个
 *   一个是 0 ~ n - 2;
 *   另一个是 1 ~ n - 1
 */
public class _213 {

    public int rob(int[] nums) {
        if (nums == null || nums.length == 0) {
            return 0;
        }
        if (nums.length == 1) {
            return nums[0];
        }
        return Math.max(rob_rob(nums, 0, nums.length - 2), rob_rob(nums, 1, nums.length - 1));
    }
    public int rob_rob(int[] nums, int start, int end) {
        int pre2 = 0, pre1 = 0;
        for (int i = start; i <= end; i++) {
            int tem = pre2;
            pre2 = Math.max(pre1 + nums[i], pre2);
            pre1 = tem;
        }
        return pre2;
    }
}
